#pragma once

#include <map>
#include <string>
#include "hidapi.h"
#include "DKhid.h"

typedef void (*DKUsbOnReceiverDataCallback)(uint8_t*, uint16_t);

class DKUSBOp
{
public:
	DKUSBOp();
	DKUSBOp(DKUsbOnReceiverDataCallback fun);
	~DKUSBOp();

	boolean Init();
	void Exit();
	boolean Open(unsigned short vid, unsigned short pid);
	boolean Write(unsigned char *buf, int size);
	boolean Write(unsigned char* buf, int size, int timeout);
	boolean Write(unsigned char* buf, int size, DKUsbOnReceiverDataCallback fun);
	boolean WriteAck();
	int Read(unsigned char* buf, size_t size, int timeout);
	void Close();
	void Print();
	void SetOnReceiverDataCallback(DKUsbOnReceiverDataCallback fun);
	boolean isOpen_;
	boolean isAutoSearch_;

	DKUsbOnReceiverDataCallback mOnReceiverData;
protected:
	DKCHid m_MyHidDevice;
	boolean Open(std::string vid, std::string pid);
	boolean Open(const char *path);
	//Key is VID+PID string value is device name
	//std::map<std::string, std::pair<std::string, std::string>> mapDev_;
	hid_device *handle_;
};

//extern DKUSBOp gDKUSBOp;